#!/usr/bin/env python

# The gui interface of pyfan
# Use PyGTK 2.0
# ppip.nk@gmail.com
# start at 2008-2-26

import pygtk
pygtk.require('2.0')
import gtk

import pyfan

class Gui:
    '''The class deal with pyfan gui'''

    def __init__(self, work = None):

        self.work = work
        self.list_number = 20
        if work != None:
            self._main_window()

    def _main_window(self):

        # Set up window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", lambda w: gtk.main_quit())
        self.window.set_title("Pyfan")

        total_box = gtk.VBox(False, 0)
        self.window.add(total_box)
        total_box.show()

        # List window part
        list_scrolled_window = gtk.ScrolledWindow()
        list_scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        list_scrolled_window.show()
        list_box = gtk.VBox()
        list_content = []

        data = self.work.list
        for i in range(20):
            list_content.append(self._statue_box(data[i]))
            list_content[i].show()
            list_box.pack_start(list_content[i], False, False, 0)
        list_box.show()
        list_scrolled_window.add_with_viewport(list_box)

        # Post box part
        postText = gtk.TextView()
        textBuffer = postText.get_buffer()
        postText.show()
        postButton = gtk.Button("140 letters left")
        postButton.show()

        postBox = gtk.VBox()
        postBox.set_border_width(3)
        postBox.pack_start(postText, True, True, 0)
        postBox.pack_start(postButton, False, False, 0)
        postBox.show()

        total_box.pack_start(list_scrolled_window)
        total_box.pack_start(postBox)

        self.window.show()
        gtk.main()

    def _statue_box(self, data):
        box =  gtk.HBox()

        profile_image = gtk.Image()
        profile_image.set_from_file("noface.jpg")
        profile_image.show()
        box.pack_start(profile_image)

        label = gtk.Label(data[3])
        label.show()
        box.pack_start(label)

        box.show()
        return box
        
    def _save_image(self):
        pass

if __name__ == "__main__":
    pyfan_gui = gui()
